/* 
Set directory 
*/

    global root ENTER DIRECTORY
	
	global data 	$root\Dta\ASER\


use "$data\aser_all", clear

keep if math != . & read != .

merge m:1 gisstatename gisdistrictname year using "$data\clean_weather_bins_hum_wbgt"

**Dropping those not matcher from using
drop if _merge == 2

drop _merge


*State ID
drop if gisstatename == "Andaman and Nicobar"

*Andhra Pradesh/Telengana
replace gisstatename = "Andhra Pradesh" if gisstatename == "Telangana"

egen gstateid = group(gisstatename)

*Creating New District Id
drop gdistid

egen gdistid = group(gisstatename gisdistrictname)


**On-track children
replace age5to16class = . if age5to16class == 99
gen age_m_grade = childage - age5to16class

gen ontrack = .
replace ontrack = 1 if age_m_grade >= 0 &  age_m_grade <= 6
replace ontrack = 0 if ontrack != 1

**Mother's education
replace motherschstd = 0 if motherschstd == 99
replace motherschstd = 0  if mothersch == 0 
replace motherschstd = 0 if motherschstd == .

**Household Type
foreach var of varlist hhtype_katcha hhtype_semi_katcha hhtype_pucca{
replace `var' = 0 if `var' == . 
replace `var' = . if year == 2006
replace `var' = . if year == 2007
}

replace hhtype_katcha = 1 if hh_type == 1 
replace hhtype_semi_katcha = 1 if hh_type == 2 
replace hhtype_pucca = 1 if hh_type == 3 


replace hhtype_semi_katcha = . if hhtype_katcha == 0 &  hhtype_semi_katcha == 0 &  hhtype_pucca == 0
replace hhtype_pucca = . if hhtype_katcha == 0 &  hhtype_pucca == 0 &  hhtype_semi_katcha == .
replace hhtype_katcha = . if hhtype_katcha == 0 &  hhtype_semi_katcha == . &  hhtype_pucca == .

**Village Indicators
foreach var of varlist vlg_pucca_road vlg_electricity_conn vlg_bank{
replace `var' = 0 if `var' == 2
replace `var' = . if year == 2006
replace `var' = . if year == 2007
}

*Total Members
winsor totalmember , gen(wtotalmember) p(0.01) 

*School Type
tab age5to16sch, gen(age5to16sch_)

replace age5to16sch_2 = 0 if age5to16sch_2 == .
replace mothersch = 0 if mothersch == .
replace hh_elec = 0 if hh_elec == . & year >2007
replace hh_phone = 0 if hh_phone == . & year >2007
replace vlg_pucca_road  = 0 if vlg_pucca_road  == . & year >2007
replace vlg_electricity_conn  = 0 if vlg_electricity_conn  == . & year >2007
replace hh_tv = 0 if hh_tv == . & year >2007


save "$data\aser_temp_analysis_ready", replace
